import Vue from 'vue'
import Vuex from 'vuex'
import menu from './modules/menu'
import role from './modules/role'
import manager from './modules/manager'
import cate from './modules/cate'
import specs from './modules/specs'
import goods from './modules/goods'
import member from './modules/member'
import banner from './modules/banner'
import seckill from './modules/seckill'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userinfo: sessionStorage.getItem('userinfo') ? JSON.parse(sessionStorage.getItem('userinfo')) : null
  },
  getters: {
    getUser(state) {
      return state.userinfo
    }
  },
  mutations: {
    REQ_USER(state, payload) {
      if (payload) {
        state.userinfo = payload
        sessionStorage.setItem('userinfo', JSON.stringify(payload))
      } else {
        sessionStorage.removeItem("userinfo")
      }
    }
  },
  actions: {
    changeUserAction({ commit }, payload) {
      commit("REQ_USER", payload)
    }
  },
  modules: {
    menu,
    role,
    manager,
    cate,
    specs,
    goods,
    member,
    banner,
    seckill
  }
})
